package com.hkd.common.api.convert;

import com.hkd.common.api.SysException;
import com.hkd.common.api.enums.IdentityCardType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author HKD
 * @date 2022/9/17 20:04
 */
@Component
public class IdentityCardTypeConvert implements Converter<Integer, IdentityCardType> {

    @Override
    public IdentityCardType convert(Integer source) {
        IdentityCardType search = IdentityCardType.search(source);

        return Optional.ofNullable(search).orElseGet(() -> {
            throw new SysException("无此证件类型");
        });
    }
}
